package com.guoguo.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.guoguo.base.PageBean;
import com.guoguo.entity.Recharge;
import com.guoguo.entity.vo.RechargeVO;
import com.guoguo.mapper.PurviewMapper;
import com.guoguo.mapper.RechargeMapper;
import com.guoguo.service.IRechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by Administrator on 2017/9/12 0012.
 */

     /*
                           _ooOoo_
                          o8888888o
                          88" . "88
                          (| -_- |)
                          O\  =  /O
                       ____/`---'\____
                     .'  \\|     |//  `.
                    /  \\|||  :  |||//  \
                   /  _||||| -:- |||||-  \
                   |   | \\\  -  /// |   |
                   | \_|  ''\---/''  |   |
                   \  .-\__  `-`  ___/-. /
                 ___`. .'  /--.--\  `. . __
              ."" '<  `.___\_<|>_/___.'  >'"".
             | | :  `- \`.;`\ _ /`;.`/ - ` : | |
             \  \ `-.   \_ __\ /__ _/   .-` /  /
        ======`-.____`-.___\_____/___.-`____.-'======
                           `=---='
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 佛祖保佑       永无BUG
        */
@Service
public class RechargeServiceImpl implements IRechargeService {
    @Autowired
    private RechargeMapper rechargeMapper;
    @Override
    public Recharge addRecharge(String rechId, String money, int rechType, int point, int timeLimit, int frequency, int sort) {
        //添加修改
        Recharge recharge = rechargeMapper.selectByPrimaryKey(rechId);
        if (recharge == null) {
            recharge = new Recharge(rechId, money, rechType, point, timeLimit, frequency, sort);
            int num=rechargeMapper.insertSelective(recharge);
            return recharge;
        } else {
            recharge.setRechType(rechType);
            recharge.setMoney(money);
            recharge.setPoint(point);
            recharge.setFrequency(frequency);
            recharge.setTimeLimit(timeLimit);
            recharge.setSort(sort);
            int num= rechargeMapper.updateByPrimaryKeySelective(recharge);
            return recharge;
        }

    }



    @Override
    public List<Recharge> getRechargeList() {
        return rechargeMapper.getRechargeList();
    }

    @Override
    public PageBean<RechargeVO> selectRechargeList(int pageNumber,int pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<RechargeVO> rechargeVos=rechargeMapper.selectRechargeList();
        return new PageBean<RechargeVO>(rechargeVos);
    }

    @Override
    public int insertSelective(Recharge recharge) {
        return rechargeMapper.insertSelective(recharge);
    }

    @Override
    public Recharge selectByPrimaryKey(String rechId) {
        return rechargeMapper.selectByPrimaryKey(rechId);
    }

    @Override
    public int deleteByPrimaryKey(String rechId) {
        return rechargeMapper.deleteByPrimaryKey(rechId);
    }


}
